﻿using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Threading.Tasks;
using OpenFileTransfer.Wpf.Database;

namespace OpenFileTransfer.Wpf.Repositories
{
    public interface IRepository<TEntity> where TEntity : class
    {
        SqliteDbContext DbContext { get; }

        Task<bool> AnyAsync(Expression<Func<TEntity, bool>> predicate); //是否有实体
        Task<IList<TEntity>> GetAsync(Expression<Func<TEntity, bool>> predicate); //获取实体列表

        Task<IList<TEntity>> GetAsync<TKey>(
            Expression<Func<TEntity, bool>> predicate,
            Expression<Func<TEntity, TKey>> keySelector,
            bool ascending = true
        ); //获取排序的实体列表

        void Add(TEntity entity); //添加实体
        void Delete(TEntity entity); //删除实体
        void Update(TEntity entity); //更新实体
        void Update(TEntity entity, params Expression<Func<TEntity, object>>[] updatedProperties); //更新实体部分属性
        Task<bool> SaveAsync(); //保存修改
    }
}
